package com.tql.test_03;

import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;

public class Test3 {
    public static void main(String[] args) {
        //集合并发不安全 List set map

        /*  List<String> list = new Vector<>();*/
        /* Set<String> set = new HashSet<>();*/
        /* Set<String> set = Collections.synchronizedSet(new HashSet<>()); //方法1.并发安全*/
        Map<String,Object> set=new ConcurrentHashMap<>();
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                set.put(Thread.currentThread().getName(),UUID.randomUUID().toString().substring(0,5));
            },"线程"+i).start();
            System.out.println(set);
            System.out.println(UUID.randomUUID().toString().substring(0,5));
        }
    }
}
